data is not inserting in my db table [closed]

Posted by Sarojit Chakraborty on Stack Overflow See other posts from Stack Overflow or by Sarojit Chakraborty
Published on 2012-10-04T20:16:58Z Indexed on 2012/10/07 9:37 UTC
Read the original article Hit count: 268

Please see my below(SubjectDetailsDao.java) code of addZoneToDb method. My debugger is nicely running upto ** session.getTransaction().commit();** code. but after that debugger stops,I do not know why it stops after that line? .And because of this i am unable to insert my data into my database table.

I don't know what to do.Why it is not inserting my data into my database table? Plz help me for this. H

Now i am getting this Error:

            Struts Problem Report

        Struts has detected an unhandled exception:

        Messages:   
        org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/event/EventSource;
        File:   org/hibernate/validator/event/ValidateEventListener.java
        Line number:    172
        Stacktraces

        java.lang.reflect.InvocationTargetException
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:601)
            com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
            com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
            com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
            com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
            org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
            com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
            com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
            com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
            com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
            org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
            org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
            org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
            org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
            java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
            java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
            java.lang.Thread.run(Thread.java:722)

        java.lang.NoSuchMethodError: org.hibernate.event.PreInsertEvent.getSource()Lorg/hibernate/event/EventSource;
            org.hibernate.validator.event.ValidateEventListener.onPreInsert(ValidateEventListener.java:172)
            org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:156)
            org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:49)
            org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
            org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
            org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
            org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
            org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
            org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
            org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
            org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
            v.esoft.dao.SubjectdetailsDAO.SubjectdetailsDAO.addZoneToDb(SubjectdetailsDAO.java:185)
            v.esoft.actions.LoginAction.datatobeinsert(LoginAction.java:53)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            java.lang.reflect.Method.invoke(Method.java:601)
            com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:441)
            com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
            com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
            com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
            com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
            com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
            org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
...............................
    ...............................

SubjectDetailsDao.java(I have problem in addZoneToDb)

            package v.esoft.dao.SubjectdetailsDAO;



            import java.text.SimpleDateFormat;
            import java.util.ArrayList; 
            import java.util.Iterator;
            import java.util.List; 
            import org.hibernate.HibernateException;
            import org.hibernate.Query;
            import org.hibernate.Session;
            import org.hibernate.SessionFactory;
            import org.hibernate.Transaction; 
            import org.hibernate.criterion.Order;  
            import com.opensymphony.xwork2.ActionSupport;

            import v.esoft.connection.HibernateUtil;
            import v.esoft.pojos.Subjectdetails;




            public class SubjectdetailsDAO extends ActionSupport
            {

                 private static Session session = null;
                    private static SessionFactory sessionFactory = null;
                    static Transaction transaction = null;
                    private String currentDate;
                    SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
                    private java.util.Date currentdate;


                    public SubjectdetailsDAO()
                    {
                        sessionFactory = HibernateUtil.getSessionFactory();  
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                        currentdate = new java.util.Date();
                        currentDate = formatter.format(currentdate);
                    }


                    public List getAllCustomTempleteRoutinesForGrid() {
                        List list = new ArrayList();

                        try {
                            session = sessionFactory.openSession();
                            list = session.createCriteria(Subjectdetails.class).addOrder(Order.desc("subjectId")).list();
                        } catch (Exception e) {
                            System.out.println("Exepetion in getAllCustomTempleteRoutines" + e);
                        } finally {
                            try {

                              //  HibernateUtil.shutdown();
                            } catch (Exception e) {
                                System.out.println("Exception In getExerciseListByLoginId Resource closing  :" + e);
                            }
                        }

                        return list;
                    }

                    //**showing list on grid   
                     private static List<Subjectdetails> custLst=new ArrayList<Subjectdetails>();
                     static int total=50;
                     static {
                            SubjectdetailsDAO cts = new SubjectdetailsDAO();
                             Iterator iterator1 = cts.getAllCustomTempleteRoutinesForGrid().iterator();
                             while (iterator1.hasNext()) 
                                {
                                 Subjectdetails get = (Subjectdetails) iterator1.next();  
                             custLst.add(get);
                                }

                     } 
                    /****************************************update Routines List by WorkId************************************/
                    public int updatesub(Subjectdetails s)
                    {
                        int updated = 0;

                        try {
                              session = sessionFactory.openSession();
                            transaction = session.beginTransaction();
                            Query query = session.createQuery("UPDATE Subjectdetails set subjectName = :routineName1  WHERE subjectId=:workoutId1");
                            query.setString("routineName1", s.getSubjectName()); 
                            query.setInteger("workoutId1", s.getSubjectId());
                            updated = query.executeUpdate();

                            if (updated != 0) {
                            }

                            transaction.commit();
                        } catch (Exception e) {
                            if (transaction != null && transaction.isActive()) {
                                try {
                                    transaction.rollback();
                                } catch (Exception e1) {
                                    System.out.println("Exception in addUser() Rollback  :" + e1);
                                }
                            }
                        } finally {
                            try {
                                session.flush();
            session.close();

                            } catch (Exception e) {
                                System.out.println("Exception In addUser Resource closing  :" + e);
                            }
                        }

                        return updated;
                    } 
                    /****************************************update Routines List by WorkId************************************/
                    public int addSubjectt(Subjectdetails s)
                    {
                        int inserted = 0;
                        Subjectdetails ss=new Subjectdetails();
                        try {
                              session = sessionFactory.openSession();
                            transaction = session.beginTransaction();  
                            ss. setSubjectName(s.getSubjectName()); 
                              session.save(ss);
                              System.out.println("Successfully data insert in database"); 
                              inserted++;
                            if (inserted != 0) {
                            }

                            transaction.commit();
                        } catch (Exception e) {
                            if (transaction != null && transaction.isActive()) {
                                try {
                                    transaction.rollback();
                                } catch (Exception e1) {
                                    System.out.println("Exception in addUser() Rollback  :" + e1);
                                }
                            }
                        } finally {
                            try {
                                session.flush();
            session.close();

                            } catch (Exception e) {
                                System.out.println("Exception In addUser Resource closing  :" + e);
                            }
                        }

                        return inserted;
                    }


                    /******************************************Get all Routines List by LoginID************************************/
                    public List getSubjects() {
                        List list = null;

                        try {
                            session = sessionFactory.openSession();
                            list = session.createCriteria(Subjectdetails.class).list();
                        } catch (Exception e) {
                            System.out.println("Exception in  getRoutineList()  :" + e);
                        } finally {
                            try {
                                 session.flush();
                                session.close();
                            } catch (Exception e) {
                                System.out.println("Exception In getUserList Resource closing  :" + e);
                            }
                        }

                        return list;
                    }
                    //---\
                    public int addZoneToDb(String countryName, Integer loginId) {
                        int inserted = 0;

                        try {
                             System.out.println("---------1--------");
                            Session session = HibernateUtil.getSessionFactory().openSession();
                            System.out.println("---------2------session--"+session);
                            session.beginTransaction();
                            Subjectdetails country = new Subjectdetails(countryName, loginId, currentdate, loginId, currentdate);
                            System.out.println("---------2------country--"+country);
                            session.save(country);
                            System.out.println("-------after save--");
                            inserted++;
                            session.getTransaction().commit();
                            System.out.println("-------after commits--");

                        } catch (Exception e) {
                            if (transaction != null && transaction.isActive()) {
                                try {
                                    transaction.rollback();
                                } catch (Exception e1) {

                                }
                            }

                        } finally {
                            try {
                            } catch (Exception e) {

                            }
                        }
                        return inserted;
                    }


                    //--

                public int  nextId()
                {
                    return total++;
                }
                public  List<Subjectdetails> buildList()
                {

                    return custLst;
                }
                public  static int count()
                {
                    return custLst.size();
                }
                public static  List<Subjectdetails> find(int o,int q)
                {
                    return custLst.subList(o, q);
                }
                public  void save(Subjectdetails c)
                {
                    custLst.add(c);
                }
                public static  Subjectdetails findById(Integer id)
                {
                    try {
                        for(Subjectdetails c:custLst)
                        {
                            if(c.getSubjectId()==id)
                            {
                                return c;
                            }
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }  
                    return null;
                }


                public  void update(Subjectdetails c)
                {
                    for(Subjectdetails x:custLst)
                    {
                        if(x.getSubjectId()==c.getSubjectId())
                        {
                            x.setSubjectName(c.getSubjectName());
                        }
                    }
                }
                public  void delete(Subjectdetails c)
                {
                    custLst.remove(c);       
                }
                public static  List<Subjectdetails> findNotById(int id, int from,int to)
                {
                    List<Subjectdetails> subLst=custLst.subList(from, to);
                    List<Subjectdetails> temp=new ArrayList<Subjectdetails>();

                    for(Subjectdetails c:subLst)
                    {
                        if(c.getSubjectId()!=id)
                        {
                            temp.add(c);
                        }
                    }
                    return temp;
                }
                public static  List<Subjectdetails> findLesserAsId(int id, int from,int to)
                {
                    List<Subjectdetails> subLst=custLst.subList(from, to);
                    List<Subjectdetails> temp=new ArrayList<Subjectdetails>();

                    for(Subjectdetails c:subLst)
                    {
                        if(c.getSubjectId()<=id)
                        {
                            temp.add(c);
                        }
                    }
                    return temp;
                }
                public static  List<Subjectdetails> findGreaterAsId(int id, int from,int to)
                {
                    List<Subjectdetails> subLst=custLst.subList(from, to);
                    List<Subjectdetails> temp=new ArrayList<Subjectdetails>();

                    for(Subjectdetails c:subLst)
                    {
                        if(c.getSubjectId()>=id)
                        {
                            temp.add(c);
                        }
                    }
                    return temp;
                }
            }

Subjectdetails.hbm.xml

                <hibernate-mapping>
                <class name="vb.sofware.pojos.Subjectdetails" table="subjectdetails" catalog="vbsoftware">
                    <id name="subjectId" type="int">
                        <column name="subject_id" />
                        <generator class="increment"/>
                    </id>
                    <property name="subjectName" type="string">
                        <column name="subject_name" length="150" />
                    </property>
                    <property name="createrId" type="java.lang.Integer">
                        <column name="creater_id" />
                    </property>
                    <property name="createdDate" type="timestamp">
                        <column name="created_date" length="19" />
                    </property>
                    <property name="updateId" type="java.lang.Integer">
                        <column name="update_id" />
                    </property>
                    <property name="updatedDate" type="timestamp">
                        <column name="updated_date" length="19" />
                    </property>
                </class>
            </hibernate-mapping>

My POJO -> Subjectdetails.java

                package v.esoft.pojos;

            // Generated Oct 6, 2012 1:58:21 PM by Hibernate Tools 3.4.0.CR1

            import java.util.Date;

            /**
             * Subjectdetails generated by hbm2java
             */
            public class Subjectdetails implements java.io.Serializable {

                private int subjectId;
                private String subjectName;
                private Integer createrId;
                private Date createdDate;
                private Integer updateId;
                private Date updatedDate;


                public Subjectdetails( String subjectName) {
                    //this.subjectId = subjectId;
                    this.subjectName = subjectName; 
                }
                public Subjectdetails() {
                }

                public Subjectdetails(int subjectId) {
                    this.subjectId = subjectId;
                }


                public Subjectdetails(int subjectId, String subjectName, Integer createrId,
                        Date createdDate, Integer updateId, Date updatedDate) {
                    this.subjectId = subjectId;
                    this.subjectName = subjectName;
                    this.createrId = createrId;
                    this.createdDate = createdDate;
                    this.updateId = updateId;
                    this.updatedDate = updatedDate;
                }
                public Subjectdetails( String subjectName, Integer createrId,
                        Date createdDate, Integer updateId, Date updatedDate) { 
                    this.subjectName = subjectName;
                    this.createrId = createrId;
                    this.createdDate = createdDate;
                    this.updateId = updateId;
                    this.updatedDate = updatedDate;
                }



                public int getSubjectId() {
                    return this.subjectId;
                }

                public void setSubjectId(int subjectId) {
                    this.subjectId = subjectId;
                }

                public String getSubjectName() {
                    return this.subjectName;
                }

                public void setSubjectName(String subjectName) {
                    this.subjectName = subjectName;
                }

                public Integer getCreaterId() {
                    return this.createrId;
                }

                public void setCreaterId(Integer createrId) {
                    this.createrId = createrId;
                }

                public Date getCreatedDate() {
                    return this.createdDate;
                }

                public void setCreatedDate(Date createdDate) {
                    this.createdDate = createdDate;
                }

                public Integer getUpdateId() {
                    return this.updateId;
                }

                public void setUpdateId(Integer updateId) {
                    this.updateId = updateId;
                }

                public Date getUpdatedDate() {
                    return this.updatedDate;
                }

                public void setUpdatedDate(Date updatedDate) {
                    this.updatedDate = updatedDate;
                }

            }

And my Sql query is

CREATE TABLE IF NOT EXISTS `subjectdetails` 
            ( `subject_id` int(3) NOT NULL,

            `subject_name` varchar(150) DEFAULT NULL,

             `creater_id` int(5) DEFAULT NULL,

            `created_date` datetime DEFAULT NULL,

            `update_id` int(5) DEFAULT NULL,

             `updated_date` datetime DEFAULT NULL,

             PRIMARY KEY (`subject_id`)
            ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql